package com.addplus.townmall.server.queue.serviceimpl;

import com.addplus.townmall.server.api.model.town.param.OrderTimeOutParam;
import com.addplus.townmall.server.api.modelenum.QueueEnum;
import com.addplus.townmall.server.api.service.queue.OrderTimeOutService;
import com.alibaba.dubbo.config.annotation.Service;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.amqp.rabbit.support.CorrelationData;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * 类名: OrderTimeOutServiceImpl
 *
 * @author zhangjiehang
 * @version V1.0
 * @date 2018/9/27 下午12:19
 * @description 类描述: 订单超时关闭消息队列接口实现类
 */
@Service(interfaceClass = OrderTimeOutService.class,async = true)
public class OrderTimeOutServiceImpl implements OrderTimeOutService{

    private final String DELAY_HEADER = "x-delay";

    @Autowired
    private RabbitTemplate rabbitTemplate;

    @Override
    public void sendOrderTimeOut(OrderTimeOutParam orderTimeOutParam) {
        rabbitTemplate.convertAndSend(QueueEnum.ORDER_QUEUE.getExchange(), QueueEnum.ORDER_QUEUE.getRoutingKey(), orderTimeOutParam, message ->{
            message.getMessageProperties().setHeader(DELAY_HEADER,orderTimeOutParam.getTimeOutSecond());
            return message;
        },new CorrelationData(orderTimeOutParam.getOrderId().toString()));
    }
}
